package sipoc.messaging.component;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.annotation.Header;
import org.springframework.integration.annotation.Payload;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.stereotype.Component;

import sipoc.license.LicenseManager;
import sipoc.model.HbResponseValue;

@Component
public class GenericHeartBeatOutboundAdapter {
	@Autowired
	private LicenseManager licenseManager;

	private static final Logger LOGGER = LoggerFactory
			.getLogger(GenericHeartBeatOutboundAdapter.class);

	@ServiceActivator(inputChannel = "genericManagerChannel", outputChannel = "transformerChannel")
	public HbResponseValue get(@Header String countryCode,
			@Header String assetId, @Payload Integer sequence) {
		LOGGER.info("Generic received hb with sequence {} for assetId {}",
				assetId, sequence);

		if (licenseManager.getLicense(countryCode, assetId) == null) {
			return HbResponseValue.INVALID_LICENSE;
		}

		return HbResponseValue.LICENSE_OK;
	}
}
